<template>
  <div class="gl_contentBox gl_heightFull">
    <div class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <el-col :span="4">
          <p>姓名</p>
          <el-input v-model="Api_GET_ClubTAManagementRegistersQO.Filter" placeholder="姓名或联系方式" size="mini" clearable @change="gettablelist()" />
        </el-col>
        <el-col :span="4">
          <p>证件号码</p>
          <el-input v-model="Api_GET_ClubTAManagementRegistersQO.IdCardNumberFilter" placeholder="证件号码" size="mini" clearable @change="gettablelist()" />
        </el-col>
        <el-col :span="4">
          <p>性别</p>
          <el-select v-model="sex" size="mini" @change="gettablelist()">
            <el-option label="全部" value="" />
            <el-option label="男" value="M" />
            <el-option label="女" value="W" />
          </el-select>
        </el-col>
        <!-- <el-col :span="4">
          <p>所属机构</p>
          <el-input v-model="Api_GET_ClubTAManagementRegistersQO.OrganizationUnitDisplayNameFilter" placeholder="所属机构" size="mini" clearable @change="gettablelist()" />
        </el-col> -->
        <el-col :span="4">
          <el-button type="primary" style="margin-top:25px" size="mini" @click="gettablelist()">筛选</el-button>
          <el-button type="warning" size="mini" @click="reset()">{{ $t('button.Reset') }}</el-button>
        </el-col>
      </el-row>
    </div>
    <el-table v-loading="loading" size="mini" :data="tableData" class="gl_table_noBorder gl_mt_10 gl_mb_15" style="width: 100%">
      <el-table-column label="序号" type="index" align="center" width="55" />
      <el-table-column label="头像" align="center" :width="95">
        <template slot-scope="{ row }">
          <PersonalImage :imgurl="row.imagePath" imgheight="60px" />
        </template>
      </el-table-column>
      <el-table-column label="姓名" prop="name" align="center" />
      <el-table-column label="性别" align="center">
        <template slot-scope="{row}">
          {{ row.genderCode === 'M'?'男':"女" }}
        </template>
      </el-table-column>
      <el-table-column label="证件号码" prop="idCardNumber" align="center" />
      <el-table-column label="所属地域" min-width="160">
        <template slot-scope="{ row }">
          {{ addressDataForCheck(row) }}
        </template>
      </el-table-column>
      <el-table-column label="联系方式" prop="phoneNumber" align="center" />
      <el-table-column label="操作">
        <template slot-scope="{ row }">
          <el-button size="mini" type="text" @click="lookorfainzation(row.id)">查看</el-button>
          <el-button size="mini" type="text" @click="clickEdit(row.id)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-row class="gl_pt_15" style="text-align: right;">
      <el-pagination
        :current-page="Api_GET_ClubTAManagementRegistersQO.Page"
        :page-size="Api_GET_ClubTAManagementRegistersQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import PersonalImage from '@/components/PersonalImage/index';
import { api_GET_ClubTAManagementRegisters } from '@/extend/api/hallswaggerApi/app.js';
import { Api_GET_ClubTAManagementRegistersQO } from '@/lib/form/hall/swaggerForm';
export default {
  components: {
    PersonalImage
  },
  data() {
    return {
      Api_GET_ClubTAManagementRegistersQO: new Api_GET_ClubTAManagementRegistersQO(),
      totalPage: 0,
      sex: '',
      loading: false,
      tableData: []
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict,
      cache: state => state.dict.cache
    })
  },
  created() {
    this.gettablelist();
    this.getDictByType(['district']);
  },
  methods: {
    // 若没有字典信息，外部可直接调用方法获取字典数据
    ...mapActions({ getDict: 'dict/getDict', getDictByType: 'dict/getDictByType' }),
    gettablelist(page) {
      this.loading = true;
      this.Api_GET_ClubTAManagementRegistersQO.GenderCode = this.sex;
      this.Api_GET_ClubTAManagementRegistersQO.Sorting = 'creationTime DESC';
      this.Api_GET_ClubTAManagementRegistersQO.Page = page || 1;
      this.Api_GET_ClubTAManagementRegistersQO.SkipCount = (this.Api_GET_ClubTAManagementRegistersQO.Page - 1) * this.Api_GET_ClubTAManagementRegistersQO.MaxResultCount;
      this.Api_GET_ClubTAManagementRegistersQO.DelegationId = this.$route.query.id;
      api_GET_ClubTAManagementRegisters(this.Api_GET_ClubTAManagementRegistersQO).then(res => {
        console.log(res);
        this.loading = false;
        this.tableData = res.items || [];
        this.totalPage = res.totalCount;
      }, error => {
        this.loading = false;
        this.$message({ type: 'error', message: (error.error && error.error.message || '') });
      });
    },
    lookorfainzation(id) {
      this.$router.push({ name: 'Member', query: {
        id: id
      }});
    },
    // 重置
    reset() {
      this.sex = '';
      this.gettablelist();
    },
    // 分页按钮
    sizeChange(MaxResultCount) {
      this.Api_GET_ClubTAManagementRegistersQO.MaxResultCount = MaxResultCount;
      this.gettablelist();
    },
    pageIndexChange(currentPage) {
      this.gettablelist(currentPage);
    },
    getStaticAvatarUrl(relativeUrl) {
      if (relativeUrl) {
        return WEB_CONFIG.VUE_APP_STATIC_FILE_RUL + relativeUrl;
      } else {
        return require('@/assets/images/face_default.png');
      }
    },
    // 编辑
    clickEdit(id) {
      this.$router.push({
        name: 'Member',
        query: {
          id: id,
          edit: true
        }
      });
    },
    // 行政所属地区
    addressDataForCheck (memberInfo) {
      const _provinceCode = memberInfo.provinceCode;
      const _cityCode = memberInfo.cityCode;
      const _countyCode = memberInfo.countyCode;
      let _provinceData;
      let _cityData;
      let _countyData;
      if (_provinceCode && this.cache.district) {
        _provinceData = this.cache.district.find(item => item.code === _provinceCode);
      }
      if (_cityCode && _provinceData) {
        _cityData = _provinceData.children.find(item => item.code === _cityCode);
      }
      if (_countyCode && _cityData) {
        _countyData = _cityData.children.find(item => item.code === _countyCode);
      }
      return `${_provinceData ? _provinceData.name : ''} ${_cityData ? _cityData.name : ''} ${_countyData ? _countyData.name : ''}`;
    }
  }

};
</script>
<style scoped>

</style>;
